<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Cart;

class shopController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function getIndex()
    {
        $datas = \DB::table('shop')->get();
        // dd($datas);die;
        return view('shop.list',['data'=>$datas]);
        
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function getGood($id)
    {


        // Cart::destroy();
        // $shop = $datas[2];
        // \DB::table('shop')->insert($datas);
        $data = \DB::table('shop')->where('id',$id) -> first();


        $arr['id'] = $data -> id;
        $arr['name'] = $data -> name;
        $arr['qty'] = 1;
        $arr['img'] = $data -> img;
        $arr['price'] = $data -> price;

        Cart::add($arr);

        $goods = Cart::content();

        return view('shop.shop',['good'=>$goods]);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function getGo()
    {
        $goods = Cart::content();

        return view('shop.shop',['good'=>$goods]);
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function getDelete()
    {
        Cart::destroy();

        return redirect('/shop');
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function getDel($name)
    {
        Cart::remove($name);

        $goods = Cart::content();

        return view('shop.shop',['good'=>$goods]);

    }
}
